import type { TableColumn } from '@/components/core/dynamic-table';
import { getDate, selectDictLabel } from '@/utils/telchina';
import { Tooltip } from 'ant-design-vue';
import { reactive } from 'vue';

// 当前页面使用的数据
export const pageDataObj = reactive({
  workOrderTypeDict: [],
  industryTypeDict: [],
  responsibleUnitDict: [],
  workOrderStatus: [],
  approveStatusDict:[],
  regionDict:[],
  infoSerrcesTypeDict:[],
  areaDict:[]
});
export type TableColumnItem = TableColumn;

// 工单代办
export const baseColumns: TableColumnItem[] = [
  {
    title: '工单编号',
    key: 'workOrderNumber',
    dataIndex: 'workOrderNumber',
    align: 'center',
    fixed: 'left',
    width: '120px',
  },
  {
    title: '办理',
    key: 'handle',
    dataIndex: 'handle',
    hideInSearch: true,
    align: 'center',
    fixed: 'left',
    width: '80px',
  },
  {
    title: '工单状态',
    key: 'workOrderStatus',
    dataIndex: 'workOrderStatus',
    align: 'center',
    customRender: ({ record }) => {
      return selectDictLabel(pageDataObj.workOrderStatus, record.workOrderStatus);
    },
    formItemProps: {
      // colProps:{
      //   span: 6,
      // },
      component: 'Select',
      componentProps: {
        options: pageDataObj.workOrderStatus,
      },
    },
  },
  {
    title: '来电号码',
    key: 'callerNumber',
    dataIndex: 'callerNumber',
    align: 'center',
    hideInSearch: true,
    width: '120px',
  },
  {
    title: '受理员',
    key: 'acceptNumber',
    dataIndex: 'acceptNumber',
    hideInSearch: true,
    align: 'center',
    width: '100px',
  },
  {
    title: '问题描述',
    key: 'problemDesc',
    dataIndex: 'problemDesc',
    align: 'center',
    hideInSearch: true,
    width: 300,
    customRender: ({ record }) => {
      return (
        <Tooltip title={record.problemDesc}>
          <div class="ellipsis" style={{ float: 'left', maxWidth: '100%' }}>
            {record.problemDesc}
          </div>
        </Tooltip>
      );
    },
  },
  {
    title: '受理时间',
    key: 'acceptTime',
    dataIndex: 'acceptTime',
    align: 'center',
    width: '180px',
    formItemProps: {
      component: 'RangePicker',
      colProps: {
        span: 6,
      },
      componentProps: {
        showTime: true,
      },
    },
  },
  {
    title: '责任单位',
    key: 'responsibleUnit',
    dataIndex: 'responsibleUnit',
    hideInSearch: true,
    align: 'center',
    customRender: ({ record }) => {
      return selectDictLabel(pageDataObj.responsibleUnitDict, record.responsibleUnit);
    },
  },
  {
    title: '报案联系人',
    key: 'contacts',
    dataIndex: 'contacts',
    hideInSearch: true,
    align: 'center',
  },
  {
    title: '联系方式',
    key: 'contactsInfo',
    hideInSearch: true,
    dataIndex: 'contactsInfo',
    align: 'center',
  },

  {
    title: '是否回访',
    key: 'returnVisit',
    dataIndex: 'returnVisit',
    hideInSearch: true,
    align: 'center',
    formItemProps: {
      // colProps:{
      //   span: 6,
      // },
      component: 'Select',
      componentProps: {
        options: [
          {
            label: '是',
            value: '1',
          },
          {
            label: '否',
            value: '2',
          },
        ],
      },
    },
    customRender: ({ record }) => {
      const isEnable = record.returnVisit == 1;
      return isEnable ? '是' : '否';
    },
  },
  {
    title: '处理期限',
    key: 'processingPeriod',
    hideInSearch: true,
    dataIndex: 'processingPeriod',
    align: 'center',
    width: 200,
    customRender: ({ record }) => {
      if (record != null && record.surplusTime > 0) {
        return record.processingPeriod + '(剩余' + getDate(record.surplusTime) + ')';
      } else if (record != null && record.surplusTime < 0) {
        return record.processingPeriod + '(超时' + getDate(record.surplusTime) + ')';
      } else {
        return record.expirationTime;
      }
    },
  },
];

// 延期申请单
export const extensionColumns: TableColumnItem[] = [
  {
    title: '工单编号',
    key: 'workOrderNumber',
    dataIndex: 'workOrderNumber',
    align: 'center',
    fixed: 'left',
    width: '120px',
  },
  {
    title: '延期单号',
    key: 'extensionNo',
    dataIndex: 'extensionNo',
    align: 'center',
    width: '120px',
  },
  {
    title: '办理',
    key: 'handle',
    hideInSearch: true,
    dataIndex: 'handle',
    align: 'center',
    width: '80px',
  },
  {
    title: '预计完成时间',
    key: 'estimatedCompletionTime',
    dataIndex: 'estimatedCompletionTime',
    align: 'center',
    hideInSearch: true,
    width: '120px',
  },
  {
    title: '延期原因',
    key: 'extensionReason',
    dataIndex: 'extensionReason',
    align: 'center',
    hideInSearch: true,
    width: 300,
    customRender: ({ record }) => {
      return (
        <Tooltip title={record.extensionReason}>
          <div class="ellipsis" style={{ float: 'left', maxWidth: '100%' }}>
            {record.extensionReason}
          </div>
        </Tooltip>
      );
    },
  },
  {
    title: '审批状态',
    key: 'approveStatus',
    dataIndex: 'approveStatus',
    align: 'center',
    width: '120px',
    hideInSearch: true,
    customRender: ({ record }) => {
      return selectDictLabel(pageDataObj.approveStatusDict, record.approveStatus);
    },
    formItemProps: {
      component: 'Select',
      componentProps: {
        options: pageDataObj.approveStatusDict,
      },
    },
  },
];


// 延期申请单
export const superviseColumns: TableColumnItem[] = [
  {
    title: '工单编号',
    key: 'workOrderNumber',
    dataIndex: 'workOrderNumber',
    align: 'center',
    width: '120px',
  },
  {
    title: '督办单号',
    key: 'superviseNo',
    dataIndex: 'superviseNo',
    align: 'center',
    width: '120px',
  },
  {
    title: '办理',
    key: 'handle',
    hideInSearch: true,
    dataIndex: 'handle',
    align: 'center',
    width: '80px',
  },
  {
    title: '督办内容',
    key: 'superviseContent',
    dataIndex: 'superviseContent',
    align: 'center',
    hideInSearch: true,
    width: 300,
    customRender: ({ record }) => {
      return (
        <Tooltip title={record.superviseContent}>
          <div class="ellipsis" style={{ float: 'left', maxWidth: '100%' }}>
            {record.superviseContent}
          </div>
        </Tooltip>
      );
    },
  },
  {
    title: '督办人',
    key: 'filledBy',
    dataIndex: 'filledBy',
    align: 'center',
    hideInSearch: true,
    width: 120
  },
  {
    title: '督办时间',
    key: 'filledTime',
    dataIndex: 'filledTime',
    align: 'center',
    hideInSearch: true,
    width: 120
  },
  {
    title: '审批状态',
    key: 'approveStatus',
    dataIndex: 'approveStatus',
    align: 'center',
    width: '120px',
    hideInSearch: true,
    customRender: ({ record }) => {
      return selectDictLabel(pageDataObj.approveStatusDict, record.approveStatus);
    },
    formItemProps: {
      component: 'Select',
      componentProps: {
        options: pageDataObj.approveStatusDict,
      },
    },
  },
];

// 延期申请单
export const disregardColumns: TableColumnItem[] = [
  {
    title: '工单编号',
    key: 'workOrderNumber',
    dataIndex: 'workOrderNumber',
    align: 'center',
    fixed: 'left',
    width: 120,
    formItemProps: {
      colProps:{
        span: 6,
      },

    },
  },
  {
    title: '办理',
    key: 'handle',
    hideInSearch: true,
    dataIndex: 'handle',
    align: 'center',
    fixed: 'left',
    width: 80,
    formItemProps: {
      colProps:{
        span: 6,
      },
    },
  },
  {
    title: '工单状态',
    key: 'workOrderStatus',
    dataIndex: 'workOrderStatus',
    align: 'center',
    customRender: ({ record }) => {
      return selectDictLabel(pageDataObj.workOrderStatus, record.workOrderStatus);
    },
    width: 120,
    formItemProps: {
      colProps:{
        span: 6,
      },
      component: 'Select',
      componentProps: {
        options: pageDataObj.workOrderStatus,
      },
    },
  },
  {
    title: '工单类型',
    key: 'workOrderType',
    dataIndex: 'workOrderType',
    align: 'center',
    width: 120,
    customRender: ({ record }) => {
      return selectDictLabel(pageDataObj.workOrderTypeDict, record.workOrderType);
    },
    formItemProps: {
      colProps: {
        span: 6,
      },
      component: 'Select',
      componentProps: {
        options: pageDataObj.workOrderTypeDict,
      },
    },
  },
  {
    title: '行业类型',
    key: 'industryType',
    dataIndex: 'industryType',
    align: 'center',
    width: 120,
    customRender: ({ record }) => {
      return selectDictLabel(pageDataObj.industryTypeDict, record.industryType);
    },
    formItemProps: {
      component: 'TreeSelect',
      colProps: {
        span: 6,
      },
    },
  },
  {
    title: '不计考核依据',
    key: 'content',
    dataIndex: 'content',
    align: 'center',
    hideInSearch: true,
    width: 300,
    customRender: ({ record }) => {
      return (
        <Tooltip title={record.content}>
          <div class="ellipsis" style={{ float: 'left', maxWidth: '100%' }}>
            {record.content}
          </div>
        </Tooltip>
      );
    },
  },
  {
    title: '申请人',
    key: 'createBy',
    dataIndex: 'createBy',
    align: 'center',
    hideInSearch: true,
    width: 120
  },
  {
    title: '申请时间',
    key: 'filledTime',
    dataIndex: 'filledTime',
    align: 'center',
    hideInSearch: true,
    width: 150
  },
  {
    title: '处理期限(小时)',
    key: 'processingPeriod',
    hideInSearch: true,
    dataIndex: 'processingPeriod',
    align: 'center',
    width: 120,
    customRender: ({ record }) => {
      return record.processingPeriod;
    },
  },
  {
    title: '审批状态',
    key: 'approveStatus',
    dataIndex: 'approveStatus',
    align: 'center',
    hideInSearch: true,
    width: '120px',
    customRender: ({ record }) => {
      return selectDictLabel(pageDataObj.approveStatusDict, record.approveStatus);
    },
    formItemProps: {
      colProps: {
        span: 6,
      },
      component: 'Select',
      componentProps: {
        options: pageDataObj.approveStatusDict,
      },
    },
  },
];



